package com.psq.core.common.ui.dialog

import android.graphics.Color
import android.graphics.drawable.ColorDrawable
import android.os.Bundle
import android.util.Log
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import androidx.fragment.app.DialogFragment
import androidx.fragment.app.FragmentManager
import cn.wufuqi.recyclerviewbindingadapter.utils.viewBindingFragment
import com.psq.core.common.R
import com.psq.core.common.databinding.DialogExceptionBinding
import java.lang.Exception

class ExceptionDialog(private val exception: Exception) : DialogFragment() {

    private val binding by viewBindingFragment(DialogExceptionBinding::bind)

    override fun onCreateView(
        inflater: LayoutInflater,
        container: ViewGroup?,
        savedInstanceState: Bundle?
    ): View? {
        dialog?.window?.setBackgroundDrawable(ColorDrawable(Color.TRANSPARENT))
        return inflater.inflate(R.layout.dialog_exception, container, false)
    }

    override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
        super.onViewCreated(view, savedInstanceState)
        binding.titleTv.text = "网络异常"
        binding.contentTv.text = "当前网络有问题，请稍后再试！"
        Log.d(this.javaClass.simpleName, "$exception")
        binding.confirmBtn.setOnClickListener {
            this@ExceptionDialog.dismiss()
        }
    }

    fun show(manager: FragmentManager) {
        show(manager, this.javaClass.simpleName)
    }
}